package com.zlsy.learning.leetcode.dahuashujujiegou.linklist;

import com.zlsy.learning.leetcode.linkedlist.l234.ListNode;

/**
 * @author zhouliang
 * @date 2020/8/8 13:42
 */
public class CreateListHead {
  /**
   * 大话数据结构 - 头插入法
   *
   * @param listNode
   * @return
   */
  public static ListNode createListHead(ListNode listNode) {
    ListNode newhead = null;
    ListNode pcur = listNode;
    while (pcur != null) {
      ListNode temp = pcur.next;
      pcur.next = newhead;
      newhead = pcur;
      pcur = temp;
    }
    return newhead;
  }

  public static void main(String[] args) {
    ListNode node = new ListNode(0);
    node.add(1);
    node.add(2);
    node.add(3);

    createListHead(node).print();
  }
}
